package org.anyin.gitee.cloud.center.upms.repository;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.anyin.gitee.cloud.center.upms.mapper.SysRoleMenuMapper;
import org.anyin.gitee.cloud.center.upms.model.SysRoleMenu;
import org.anyin.gitee.cloud.lib.core.web.BaseRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class SysRoleMenuRepository extends BaseRepository<SysRoleMenuMapper, SysRoleMenu> {

    public List<String> getPermissionListByUserId(Long userId){
        return baseMapper.getPermissionListByUserId(userId);
    }

    public List<Long> getMenuIdListByRoleId(Long roleId){
        return baseMapper.getMenuIdListByRoleId(roleId);
    }

    public void deleteByRoleId(Long roleId){
        QueryWrapper<SysRoleMenu> wrapper = new QueryWrapper<>();
        wrapper.eq("role_id", roleId);
        baseMapper.delete(wrapper);
    }

    public void batchInsert(List<SysRoleMenu> sysRoleMenuList){
        for(SysRoleMenu entity : sysRoleMenuList){
            baseMapper.insert(entity);
        }
    }
}
